#ifndef TRACKSQL_H
#define TRACKSQL_H

class ODBCPool;
class ODBCConnection;
class MissingGameNums;

#include "lib.h"
#include "accountinfo.h"
#include "localCurrency.h"

#define PIDLEN		8
#define PID			String

#define PLAYERCLASSLEN		255
#define MAXSESSIONIDLEN		19


typedef char SESSIONID[MAXSESSIONIDLEN + 1];	// +1 for '\0'

//
// All money values are in cents (100 == $1, 25 == $.25, 1 == $.01)
//

class TrackSQL
{
	public:
		TrackSQL(const String& dsn, const String& dblogin, const String& dbpasswd);
		virtual ~TrackSQL();

		virtual bool8 initOK();

		void lock() { }
		void unlock() { }

		//
		// All functions that return a value will return a SQLError
		// (or a subclass' equivalent)
		//
		enum SQLError
		{
			NoError, NoConnection, InitError, ExecFailed,

			FIRST_GAME_ERROR
		};

		//see the PlayerLogoutTypes table and "stdncerr.h"
		enum LogoutType
		{
			AdminLogout = 0x07,
			AutoLogout	= 0x08,
            NormalLogout= 0x09  // kharmon.  11-29-07.  #20435.  Need to handle case where player logged out, but for some reason they're still playing!
		};

		int32 validateLogin(const String& login, SESSIONID sessionID, PID& pid, int32 token=0, bool8* correcttoken=0);
		int32 validateSession(const PID& pid, SESSIONID sessionID);

		// CSN-7075: New Authentication
		bool8 createRTGSession(bool8 forMoney, const String& login, SESSIONID sessionID, String ClientID);

		int32 getBalance(int32 casinoId, const PID& pid, bool8 forMoney,
			int32* balance, int32* comp, int32 *bonusBalance = 0, int32 *playthroughBalance = 0);

		//RPF20100907
		int32 putLobbyRequest(int32 casinoID, const PID& pid,int reqtype);
		int32 getLobbyRequest(int32 casinoId, const PID& pid,String& strResult,int reqtype);

		int32 adjustBalance(int32 casinoId, const PID& pid, bool8 forMoney,
			int32 amount, int32* newBalance, int32* comp);

		int32 getPlayerLimits(const PID& pid, int32 gameId, uint8 machId,
			int32* minBet, int32* maxBet, int32* compFactor);

        bool8 getAccountInfo( int32 casinoId, const String& login, AccountInfo *pInfo );

		int32 getLocale( localCurrency *localCurr, int32 *chipValues = 0);

		void addBadPacket(int32 gameid, uint8 machid, const String& error_reason, int32 severity, const PID& pid, char MessageType, uint8* msgbuf, int32 msglength);

		enum EmailConstants
		{
			EC_MAXNAMEFROM = 100,
			EC_MAXEMAILFROM = 100,
			EC_MAXEMAILTO = 100,
			EC_MAXSUBJECT = 100,
			EC_MAXDATE = 32,
			EC_MAXIP = 16,
			EC_MAXBCCEMAILADDRESS = 100

		};
		String getEmailMsg(int32 casinoId, int32 skinId, const PID& pid, int32 emailId,
                           String& nameFrom, String& emailFrom, String& emailTo,
                           String& sBccEmailAddress, String& subject, bool8 * bEmailAsHtml);

		String getEndOfSessionEmailMsg(int32 notificationID, SESSIONID sessionID, int32* msglen,
			String& nameFrom, String& emailFrom, String& emailTo, String& subject);

		bool8 getSystemEmailRouting(ODBCConnection* conn, int32 msgID,
							String& nameFrom, String& emailFrom, String& emailTo, String& subject);

        int32 getEmailAddress(int32 casinoId, const PID& pid,
			char* email, int32 maxEmailLenIncludingNull);

		int32 getCustomFeatures(uint8 * mobile, String * affSubmitURL,
				String * endOfSessionURL, uint8 * playhistoryDisabled);

		bool8 isGameEnabled(int32 gameId, uint8 machId);

		ODBCConnection* getConn();

		// CSN-7075: New Authentication
		void logout(int32 casinoId, const PID& pid, bool8 forMoney, const String& IPAddress, SESSIONID sessionID);

		// CSN-7076: New Authentication (fun play)
		bool8 getAvailableFunID( String& sFunID );

		#ifdef DEBUGSPIN
		bool8 isFreeFromAuthentication(String pid);
		#endif

	protected:
		ODBCPool*			pool;
		String				dbdsn;
		String				dblogin;
		String				dbpasswd;
};

#endif

